package leetcode.秋招.去哪儿;


import java.util.Arrays;
import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/10/13 15:57
 * @description：
 */
public class Main2 {
    public static void main(String[] args) throws Exception {
        ArrayStack<Object> OPTR = new ArrayStack<>();
        ArrayStack<Object> OPND = new ArrayStack<>();
        Scanner in = new Scanner(System.in);
        String trim = in.nextLine();
        trim = trim.replace(" ", "");
        ListEvaluate listEvaluate = new ListEvaluate(trim);
        int sum = listEvaluate.EvaluateExpression(OPTR, OPND);
        System.out.println(sum);
    }
}

class ListEvaluate {
    private static String expression;
    private static int index = 0;
    private static char c;

    public ListEvaluate(String expression) {
        this.expression = expression + "#";
        c = expression.charAt(index);
    }

    public boolean isDight(char c) {
        if (c >= '0' && c <= '9') return true;
        return false;
    }

    public int operate(char x, int a, int b) {
        int sum = 0;
        switch (x) {
            case '+' : {sum = a + b; break;}
            case '-' : {sum = a - b; break;}
            case '*' : {sum = a * b; break;}
            case '/' : {sum = a / b; break;}
        }
        return sum;
    }

    public int EvaluateExpression(ArrayStack optr, ArrayStack opnd) throws Exception {
        optr.push('#');
        int num = 0;
        char x;
        while (c != '#' || (char) optr.getTop() != '#') {
            if (c == '(') {
                c = expression.charAt(++index);
                int sum = EvaluateExpression(new ArrayStack(), new ArrayStack());
                opnd.push(sum);
                if (opnd.stackLength() == 2) {
                    if ((char)optr.getTop() == '#') {
                        throw new Exception("表达式错误");
                    } else {
                        x = (char) optr.pop();
                        int b = (int) opnd.pop();
                        int a = (int) opnd.pop();
                        opnd.push(operate(x, a, b));
                    }
                }
            }
            if (c == ')' && (char) optr.getTop() == '#') {
                c = expression.charAt(++index);
                return (int) opnd.getTop();
            }

            if (isDight(c)) {
                num = (int)(c - '0');
                opnd.push(num);
                if (opnd.stackLength() == 2) {
                    if ((char) optr.getTop() == '#') {
                        throw new Exception("表达式错误");
                    } else {
                        x = (char) optr.pop();
                        int b = (int) opnd.pop();
                        int a = (int) opnd.pop();
                        opnd.push(operate(x, a, b));
                    }
                }
                c = expression.charAt(++index);
            } else if (c != '#' && c != '(' && c != ')') {
                optr.push(c);
                c = expression.charAt(++index);
            }
        }
        return (int) opnd.getTop();
    }
}
class ArrayStack<T> {
    private int max_size;
    private T[] array;
    private int top;

    public ArrayStack() {
        this.max_size = 100;
        array = (T[]) new Object[max_size];
        this.top = -1;
    }

    public ArrayStack(int max_size) {
        this.max_size = max_size;
        array = (T[]) new Object[max_size];
        this.top = -1;
    }

    public void push(T t) {
        top++;
        if (top > array.length - 1) {
            T[] copy = Arrays.copyOf(array, max_size * 2);
            array = copy;
        }
        array[top] = t;
    }

    public T pop() throws Exception {
        if (top >= 0) {
            return array[top--];
        } else {
            throw new Exception("空栈");
        }
    }

    public T getTop() throws Exception {
        if (top < 0) throw new Exception("空栈");
        else return array[top];
    }

    public boolean isEmpty() {
        return top == -1;
    }

    public int stackLength() {
        return top + 1;
    }
}
//(+(+(+12)(+34))(+(+56)(+78)))